/*
 * @lc app=leetcode.cn id=228 lang=cpp
 *
 * [228] 汇总区间
 */

// @lc code=start
class Solution
{
public:
  vector<string> summaryRanges(vector<int>& nums)
  {
    int n = nums.size();
    vector<string> intervals;
    for (int i = 0; i < n;) {
      int j = i + 1;
      for (int step = 1; j < n && nums[i] + step == nums[j]; ++step)
        ++j;
      if (j - i > 1)
        intervals.push_back(to_string(nums[i]) + "->" + to_string(nums[j - 1]));
      else
        intervals.push_back(to_string(nums[i]));
      i = j;
    }
    return intervals;
  }
};
// @lc code=end
